public class Solution414 {
    public int thirdMax(int[] nums) {
        Integer a=null,b=null,c=null;
        for (int num : nums) {
            if (a==null){
               a=num;
               continue;
            }
            if (b==null&&a.intValue()!=num){
                b=num;
                continue;
            }
            if (c==null&&a.intValue()!=num&&b.intValue()!=num){
                c=num;
                continue;
            }
            if (a.intValue()==num||b.intValue()==num||c.intValue()==num){
                continue;
            }
            if (a.intValue()>num&&b.intValue()>num&&c.intValue()>num){
                continue;
            }
            if (a>b){
                Integer t=a;
                a=b;
                b=t;
            }
            if (a>c){
                Integer t=a;
                a=c;
                c=t;
            }
            a=new Integer(num);
        }
        if (a!=null&&b!=null&&c!=null){
            Integer min=a;
            if (a>b){
                min=b;
            }
            if (min>c){
                min=c;
            }
            return min;
        }else if (b!=null){
            return a>b?a.intValue():b.intValue();
        }else {
            return a.intValue();
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution414().thirdMax(new int[]{3,2,1}));
    }
}
